package com.example.education.Controller;


import com.example.education.Bean.ForeignCollegeInfo;
import com.example.education.Bean.StudentInfo;
import com.example.education.Bean.packaginggroup.PackagingString;
import com.example.education.Mapper.ForeignCollegeInfoMapper;
import com.example.education.service.ForeignCollegeInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.Cacheable;

import java.util.ArrayList;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 姚
 * @since 2023-03-27
 */
@RestController
@RequestMapping("/foreigncollege")
@CrossOrigin
public class ForeignCollegeInfoController {

    @Autowired
    private ForeignCollegeInfoMapper foreignCollegeInfoMapper;
    @Autowired
    private ForeignCollegeInfoService foreignCollegeInfoService;


    @PostMapping
    public Integer save(@RequestBody(required = false) ForeignCollegeInfo foreignCollegeInfo) {//将传回来的json对象转

        return foreignCollegeInfoService.insert(foreignCollegeInfo);
    }

    //根据学校名字查找学校
    @PostMapping("/select")
    @Cacheable(value = "foreignCollegeInfo")
    public ForeignCollegeInfo select(@RequestBody(required = false) PackagingString packageString) {
        ForeignCollegeInfo foreignCollegeInfo = foreignCollegeInfoService.select(packageString.getString());
        System.out.println(foreignCollegeInfo);
        return foreignCollegeInfo;
    }

    //根据地区查这个地区的所有学校
    @PostMapping("/selectByLocation")
    @Cacheable(value = "foreignCollegeInfo")
    public ArrayList<ForeignCollegeInfo> selectByLocation(@RequestBody(required = false) PackagingString packageString) {
        ArrayList<ForeignCollegeInfo> list = foreignCollegeInfoService.selectByLocation(packageString.getString());
        System.out.println(list);
        return list;
    }

    //根据相应的学生平均分推荐相应的国外学校
    @PostMapping("/find")
    public ArrayList<ForeignCollegeInfo> find(@RequestBody(required = false) StudentInfo studentInfo) {
        ArrayList<ForeignCollegeInfo> list = foreignCollegeInfoService.selectByAverageScore(studentInfo);
        System.out.println(list);
        return list;
    }


}

